@extends("admin.layout.common")

@section('content')
    <link rel="stylesheet" href="{{asset('css/finance/sub-accountStatement.css')}}">
    <div class="content">
        <p class="tongzhi"><i class="iconfont icon laba">&#xe914;</i>{{getArticleByDepartmentId()}}</p>
        <h1 class="h1">财务分账中心</h1>
        <!-- 公共结束 -->
        <div class="mon">
            <div class="mon_left">
                <form action="accountStatement" method="post">
                    {{csrf_field()}}
                    <label for="">指定人分账：<input type="text" name="phone" placeholder="请输入指定人的电话号" class="input" style="height: 30px"></label>
                    <label for="">期间设置</label>
                    <input type="month" name="time" style="height:30px;" required/>
                    <label for="">（不包含已生成的期间）<button type="submit" value="" class="jisuan btn_fenzhang li_left layui-this">开始计算</button></label>
                </form>
            </div>
            <div class="mon_right">
                <button type="button" class="btn_fenzhang jujue"><a href="{{url('admin/reaccount')}}">拒绝分账{{$count}}</a></button>
            </div>
        </div>
        <div class="table_box layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="music" >
                <ul class="layui-tab-title">
                    <li class="li_left layui-this"><span>音<br/>乐<br/>人</span></li>
                    <li class="li_center"><span>代<br/>理</span></li>
                    <li class="li_right"><span>指<br/>定<br/>人</span></li>
                </ul>
            </div>
            <div class="table_boxbig layui-tab-content" style="width:100%;">
                <div class="table_left layui-tab-item" style="display:none;">
                    <form method="post" id="musicForm1">
                        {{csrf_field()}}
                        <label for="">期间设置</label>
                        <input type="month" name="time" style="height:30px;"/>
                        <button type="button" value="" class="jisuan btn_fenzhang li_left layui-this" onclick="typeSearch(1)">搜索</button>
                    </form>
                    <table border="1" class="table_music" id="musicTable">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>音乐人</th>
                                <th>合计收入</th>
                            </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>
                <div class="table_center layui-tab-item" style="display:none;">
                    <form method="post" id="musicForm2">
                        {{csrf_field()}}
                        <label for="">期间设置</label>
                        <input type="month" name="time" style="height:30px;"/>
                        <button type="button" value="" class="jisuan btn_fenzhang li_left layui-this" onclick="typeSearch(2)">搜索</button>
                    </form>
                    <table border="1" class="table_music" id="agentTable">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>代理人</th>
                                <th>代理级别</th>
                                <th>合计收入</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="table_right layui-tab-item" style="display:none;">
                    <form method="post" id="musicForm3">
                        {{csrf_field()}}
                        <label for="">期间设置</label>
                        <input type="month" name="time" style="height:30px;"/>
                        <button type="button" value="" class="jisuan btn_fenzhang li_left layui-this" onclick="typeSearch(3)">搜索</button>
                    </form>
                    <table border="1" class="table_music" id="privateTable">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>音乐人</th>
                            <th>合计收入</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <script src="{{URL::asset('js/finance/sub-accountStatement.js')}}"></script>
@endsection
<script>
    function typeSearch(type){
        $.post('{{url('admin/typeSearch')}}',$("#musicForm"+type).serialize()+"&"+"type="+type,function(data){
            if(type==1){
                if(data[0]['user_id']) {
                    var tr = '';
                    $('#musicTable tbody').html('');
                    for (var i = 0; i < data.length; i++) {
                        tr += "<tr><td>" + data[i]['user_id'] + "</td><td>" + data[i]['user']['real_name'] + "</td><td>" + data[i]['countMoney'] + "</td></tr>"
                    }
                }
                $('#musicTable tbody').append(tr);
            }
            if(type==2){
                if(data[0]['agent_id']) {
                    var tr = '';
                    $('#agentTable tbody').html('');
                    for (var i = 0; i < data.length; i++) {
                        tr += "<tr><td>" + data[i]['agent_id'] + "</td><td>" + data[i]['agent']['simple_name'] + "</td><td>" + data[i]['agent']['scale'] + "</td><td>" + data[i]['countMoney'] + "</td></tr>"
                    }
                }
                $('#agentTable tbody').append(tr);
            }
            if(type==3){
                if(data[0]['user_id']) {
                    var tr = '';
                    $('#privateTable tbody').html('');
                    for (var i = 0; i < data.length; i++) {
                        tr += "<tr><td>" + data[i]['user_id'] + "</td><td>" + data[i]['user']['real_name'] + "</td><td>" + data[i]['countMoney'] + "</td></tr>"
                    }
                }
                $('#privateTable tbody').append(tr);
            }
        })
    }
</script>
